package com.community.http.exception;

import com.community.http.vo.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import org.yaml.snakeyaml.constructor.DuplicateKeyException;

@RestControllerAdvice
@Slf4j
public class CommonExceptionHandler {

    /**
     * 处理自定义异常
     */
    @ExceptionHandler(CommunityException.class)
    public Result handleRRException(CommunityException e){
        log.error(e.getMessage(), e);
        return Result.ERROR(e.getMessage());
    }

    @ExceptionHandler(DuplicateKeyException.class)
    public Result handleDuplicateKeyException(DuplicateKeyException e){
        log.error(e.getMessage(), e);
        return Result.ERROR("数据库中已存在该记录");
    }


}
